#include "wa_keys_drv.h"
#include "zkeys.h"
#include "wa_misc.h"
#include "wa_input.h"


static void wa_keys_drv_up_press_callback(void)
{
	wa_input_send_sign(WA_SIGNAL_USER_KEY_UP);
}

static void wa_keys_drv_down_press_callback(void)
{
	wa_input_send_sign(WA_SIGNAL_USER_KEY_DOWN);
}

static void wa_keys_drv_left_press_callback(void)
{
	wa_input_send_sign(WA_SIGNAL_USER_KEY_LEFT);
}

static void wa_keys_drv_right_press_callback(void)
{
	wa_input_send_sign(WA_SIGNAL_USER_KEY_RIGHT);
}

static void wa_keys_drv_ok_press_callback(void)
{
	wa_input_send_sign(WA_SIGNAL_USER_KEY_ENTER);
}

static void wa_keys_drv_esc_press_callback(void)
{
	wa_input_send_sign(WA_SIGNAL_USER_KEY_ESC);
}

void wa_keys_drv_init(void)
{
	zkeys_init();
	
	zkeys_callback_set(ZKEYS_KEY_UP, ZKEYS_CB_PRESS, wa_keys_drv_up_press_callback);
	zkeys_callback_set(ZKEYS_KEY_UP, ZKEYS_CB_RELEASE, NULL);
	zkeys_callback_set(ZKEYS_KEY_UP, ZKEYS_CB_LONG_PRESS, NULL);
	zkeys_long_press_set(ZKEYS_KEY_UP, 0xffff, 0xffff);
	
	zkeys_callback_set(ZKEYS_KEY_DOWN, ZKEYS_CB_PRESS, wa_keys_drv_down_press_callback);
	zkeys_callback_set(ZKEYS_KEY_DOWN, ZKEYS_CB_RELEASE, NULL);
	zkeys_callback_set(ZKEYS_KEY_DOWN, ZKEYS_CB_LONG_PRESS, NULL);
	zkeys_long_press_set(ZKEYS_KEY_DOWN, 0xffff, 0xffff);
	
	zkeys_callback_set(ZKEYS_KEY_LEFT, ZKEYS_CB_PRESS, wa_keys_drv_left_press_callback);
	zkeys_callback_set(ZKEYS_KEY_LEFT, ZKEYS_CB_RELEASE, NULL);
	zkeys_callback_set(ZKEYS_KEY_LEFT, ZKEYS_CB_LONG_PRESS, NULL);
	zkeys_long_press_set(ZKEYS_KEY_LEFT, 0xffff, 0xffff);
	
	zkeys_callback_set(ZKEYS_KEY_RIGHT, ZKEYS_CB_PRESS, wa_keys_drv_right_press_callback);
	zkeys_callback_set(ZKEYS_KEY_RIGHT, ZKEYS_CB_RELEASE, NULL);
	zkeys_callback_set(ZKEYS_KEY_RIGHT, ZKEYS_CB_LONG_PRESS, NULL);
	zkeys_long_press_set(ZKEYS_KEY_RIGHT, 0xffff, 0xffff);
	
	zkeys_callback_set(ZKEYS_KEY_OK, ZKEYS_CB_PRESS, wa_keys_drv_ok_press_callback);
	zkeys_callback_set(ZKEYS_KEY_OK, ZKEYS_CB_RELEASE, NULL);
	zkeys_callback_set(ZKEYS_KEY_OK, ZKEYS_CB_LONG_PRESS, NULL);
	zkeys_long_press_set(ZKEYS_KEY_OK, 0xffff, 0xffff);
	
	zkeys_callback_set(ZKEYS_KEY_ESC, ZKEYS_CB_PRESS, wa_keys_drv_esc_press_callback);
	zkeys_callback_set(ZKEYS_KEY_ESC, ZKEYS_CB_RELEASE, NULL);
	zkeys_callback_set(ZKEYS_KEY_ESC, ZKEYS_CB_LONG_PRESS, NULL);
	zkeys_long_press_set(ZKEYS_KEY_ESC, 0xffff, 0xffff);
	
	wa_input_enable(wa_ok);
}

void wa_keys_drv_loop(void)
{
	zkeys_loop();
}

